package com.alliky.core.global;

import com.alliky.core.entity.vo.UserVO;
import com.alliky.core.util.SPUtils;


/**
 * ================================================
 *
 * @Description: 描述全局变量
 * @Author: wxianing
 * @Date: 2023/1/6 17:02
 * ================================================
 */
public final class Global {

    /**
     * 常量类在此定义
     */
    public static class CONST {
        public static final String WECHAT_KEY = "8482195JFDA0391";
    }

    /**
     * EventBus,Activity回调等Code
     */
    public static class CODE {
        public static final int CODE_REFRESH = 0x01;
    }

    /**
     * 页面跳转、SP等KEY
     */
    public static class KEY {
        //用户信息
        public static final String USER_INFO = "user_info";
        //用户名
        public static final String USERNAME = "username";
        //密码
        public static final String PASSWORD = "password";
        //token
        public static final String TOKEN = "token";
        //标题
        public static final String TITLE = "title";
        //URL链接
        public static final String URL = "url";

        public static final String USER = "user";
    }

    public static class UserManage {
        public static String getToken() {
            return SPUtils.getInstance().getString(KEY.TOKEN);
        }

        public static void saveToken(String token) {
            SPUtils.getInstance().put(KEY.TOKEN, token);
        }

        public static UserVO getUser() {
            return SPUtils.getInstance().getObject(KEY.USER, UserVO.class);
        }

        public static void saveUser(UserVO userVO) {
            SPUtils.getInstance().put(KEY.USER, userVO);
        }

        public static void clearUser() {
            SPUtils.getInstance().remove(KEY.USER);
            SPUtils.getInstance().remove(KEY.TOKEN);
        }
    }
}
